﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Resources;
using Wicresoft.RDW.Presentation;
using Wicresoft.RDW.Utility;

namespace Wicresoft.RDW.UserControls
{
    public partial class LocationLabControl : System.Web.UI.UserControl
    {
        public bool Vertical
        {
            get
            {
                if (ViewState["Vertical"] == null)
                    return false;
                return (bool)ViewState["Vertical"];
            }
            set
            {
                ViewState["Vertical"] = value;
            }
        }
        public bool Enabled
        {
            get
            {
                if (ViewState["Enable"] == null)
                    return true;
                return (bool)ViewState["Enable"];
            }
            set
            {
                ViewState["Enable"] = value;
            }
        }
        public bool EnableValidation
        {
            get
            {
                if (ViewState["EnableValidation"] == null)
                    return false;
                return (bool)ViewState["EnableValidation"];
            }
            set
            {
                ViewState["EnableValidation"] = value;
            }
        }
        public string LocationValue
        {
            get
            {
                return ddlLocation.SelectedValue;
            }
            set
            {
                ddlLocation.SelectedValue = value;
            }
        }
        public string LabValue
        {
            get
            {
                return txtLab.Text.Trim();
            }
            set
            {
                txtLab.Text = value;
            }
        }
        public bool IsRemovePleaseSelect
        {
            get
            {
                if (string.Equals(HiddenForPleaseSelect.Value.Trim(), "true", StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
                return false;
            }
            set
            {
                HiddenForPleaseSelect.Value = value.ToString();
            }
        }
        protected BasePage BasePage
        {
            get
            {
                return this.Page as BasePage;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                phVertical.Visible = Vertical;
                phHorizon.Visible = !Vertical;
                rfvLab.Enabled = EnableValidation;
                rfvLocation.Enabled = EnableValidation;
                ddlLocation.Enabled = Enabled;
                ddlLab.Enabled = Enabled;
                InitResource();
                InitControl();
            }
        }
        protected void InitResource()
        {
            rfvLocation.ErrorMessage = NameResource.Location_Name + CommonResource.NotNull;
            rfvLab.ErrorMessage = NameResource.Lab_Name + CommonResource.NotNull;
        }
        protected void InitControl()
        {
            ddlLocation.DataValueField = "LocationId";
            ddlLocation.DataTextField = BasePage.Language == Utility.Language.CN ? "Name_CN" : "Name_EN";
            ddlLocation.DataSource = LocationPresent.GetList();
            ddlLocation.DataBind();

            if (!IsRemovePleaseSelect)
            {
                ddlLocation.Items.Insert(0, new ListItem(CommonResource.PleaseSelect, ""));
            }
            

            if (BasePage.PageStatus == PageStatus.Edit)
            {
                ddlLab.DataValueField = "LabId";
                ddlLab.DataTextField = "Name";
                ddlLab.DataSource = LabPresent.GetList();
                ddlLab.DataBind();
            }
            if (!IsRemovePleaseSelect)
            {
                ddlLab.Items.Insert(0, new ListItem(CommonResource.PleaseSelect, ""));
                ddlLab.SelectedValue = txtLab.Text;
            }
            //phScript.Visible = true;
        }
    }
}
